package org.saxion.saktiehuis.service;

import org.saxion.saktiehuis.dao.GenericDao;
import org.saxion.saktiehuis.model.Order;
import org.saxion.saktiehuis.model.OrderItem;
import org.saxion.saktiehuis.model.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Transactional
public class OrderItemService {
	@Autowired
	private GenericDao<OrderItem, Long> orderItemDao;

	public OrderItemService() {
		super();
	}

	@Transactional(propagation = Propagation.REQUIRES_NEW)
	public boolean save(Order order, Product product, Integer amount) {
		OrderItem oItem = new OrderItem(order, product, amount);
		return (orderItemDao.save(oItem) != null) ? true : false;
	}
}
